<!--
 * @Author: Zhouxin 2201_75539691@noreply.gitcode.com
 * @Date: 2024-12-02 14:25:36
 * @LastEditors: Zhouxin 2201_75539691@noreply.gitcode.com
 * @LastEditTime: 2024-12-02 16:12:30
 * @FilePath: \2024.12.2-day12-工厂模式 自定义构造函数 this\2.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /**
 * 工厂模式 集中管理 高效 
 */
        // function createStudent(name, age, sex) {
        //     var obj = new Object(); //new 构造函数();
        //     obj.name = name;
        //     obj.age = age;
        //     obj.sex = sex;
        //     obj.speak = function () {
        //         console.log('我要学习,学习使我快乐,学习让我成长!');
        //     }
        //     return obj;
        // }
        // var stu1 = createStudent('小明', 99, 'Man');

        // console.log(stu1 instanceof createStudent); // false
        // console.log(stu1 instanceof Object);        // true

        function Student(name, age, sex) {
            this.name = name;
            this.age = age;
            this.sex = sex;
            this.speak = function () {
                console.log('我要学习, 学习使我快乐, 学习让我成长! 我叫 ' + this.name);
            };
        }

        var stu3 = new Student('张三', 18, 'Man');

        console.log(stu3 instanceof Student); // true
        console.log(stu3 instanceof Object);  // true

    </script>
</body>

</html>